/*************************************************
Author: byron
Date: 01/31/2013
Description:
Notes: 
*************************************************/

#ifndef __CTreasureMgr_h__
#define __CTreasureMgr_h__

#include "commclass.h"
#include "CTreasureCfg.h"
#include "MsgPartnerInfo.pb.h"

class MsgObjBase;
class CStatusList;
class MsgGridItemInfo;
class MsgReqTreasure;
class MsgReqGMPlayer;
class MsgAnsOtherInfo;
class MsgAnsGMPlayer;
class MsgTreasureUnit;
class MsgTreasureDetail;
class CPlayerOnlineData;
class MsgAnsItemDetailInfos;

class CTreasureMgr
{
public:
    enum CMD_TREASURE_SUB_MAP{
        CMD_TREASURE_SUB_UP_LEVEL = 1,      //秘宝升级
        CMD_TREASURE_SUB_PUT_ON = 2,        //秘宝穿上
        CMD_TREASURE_SUB_TAKE_OFF = 3,      //秘宝脱下
    };

    enum TREASURE_HOST_POS_MAP{
        TREASURE_HOST_POS_NULL = 0,      //秘宝未装配
        TREASURE_HOST_POS_ONE = 1,       //第一装配位
        TREASURE_HOST_POS_TWO = 2,       //第二装配位
    };

    enum TREASURE_CONFIG_ID_TAG
    {
        TREASURE_CFG_ID_SELF_ANGER = 1,      //隆基努斯长矛
        TREASURE_CFG_ID_ENEMY_HP = 2,        //断钢巨剑
        TREASURE_CFG_ID_BEING_ATK = 3,       //恶魔之牙
        TREASURE_CFG_ID_ENEMY_DIE = 4,       //诺顿剑
        TREASURE_CFG_ID_GROUP_ATK = 5,       //圣洁圣杯
        TREASURE_CFG_ID_GET_HURT = 6,        //光荣之手
        TREASURE_CFG_ID_LOW_BLOOD = 7,       //时间沙漏
        TREASURE_CFG_ID_SOLOMON_KEY = 8,     //所罗门的钥匙
        TREASURE_CFG_ID_FATE_DICE = 9,       //命运之骰
        TREASURE_CFG_ID_SELF_DIE = 10,       //厄运水晶球
    };

    CTreasureMgr()
    {
    }

    virtual ~CTreasureMgr() 
    {
    }

    int LoadConfig(const char* szLogPath);

    int AddTreasureCfg(CTreasureCfgData& stCfgData);

    int FindTreasureCfg(int iResID);

    CTreasureCfgData& GetTreasureCfg(int iIndex);

    int AddTreasureUpCfg(CTreasureUpCfgData& stCfgData);

    int FindTreasureUpCfg(short shLevel);

    CTreasureUpCfgData& GetTreasureUpCfg(int iIndex);

    bool IsValidTreasureID(short shResID);

    int FindTreasureIndex(short shResID, CPlayerDetailInfo& stPlayerDetail);

    CTreasureUnit& GetTreasureUnit(int iIndex,
            CPlayerDetailInfo& stPlayerDetail);

    bool IsTreasureExist(CTreasureUnit& stTreasureUnit);

    bool IsTreasureOnPut(CTreasureUnit& stTreasureUnit);

    int ChkTreasureInfo(short shResID, CPlayerDetailInfo& stPlayerDetail);

    int CalcTreasureAttr(CPlayerDetailInfo& stPlayerDetail,
         CPlayerAttr& stBaseAttr, char chHostType, unsigned int uiHostID);

    int RecalcHostAttr(CTreasureUnit& stTreasureUnit,
        CPlayerBaseInfo& stPlayerBase, CPlayerDetailInfo& stPlayerDetail,
        CPlayerOnlineData& stPlayerOnline);

    int TreasureUpLevel(CPlayerBaseInfo& stPlayerBase,
            CPlayerDetailInfo& stPlayerDetail, 
            CPlayerOnlineData& stPlayerOnline, MsgReqTreasure& stReq);

    int PutOnTreasureUnit(CTreasureUnit& stTreasureUnit,
            const MsgTreasureUnit& stMsgTreasureUnit);

    int CanPutOnTreasure(char chHostType, char chHostPos, unsigned int uiHostID,
            CPlayerBaseInfo& stPlayerBase, CPlayerDetailInfo& stPlayerDetail,
            CTreasureUnit& stSourceUnit);

    int ChkTreasurePutOn(CPlayerBaseInfo& stPlayerBase,
            CPlayerDetailInfo& stPlayerDetail,
            const MsgTreasureUnit& stMsgTreasureUnit,
            CTreasureUnit& stSourceUnit);

    int TreasurePutOn(CPlayerBaseInfo& stPlayerBase,
            CPlayerDetailInfo& stPlayerDetail,
            CPlayerOnlineData& stPlayerOnline, MsgReqTreasure& stReq);

    int ClearTreasureUnit(CTreasureUnit& stTreasureUnit);

    int TreasureTakeOff(CPlayerBaseInfo& stPlayerBase,
            CPlayerDetailInfo& stPlayerDetail,
            CPlayerOnlineData& stPlayerOnline, MsgReqTreasure& stReq);

    void GetBriefTreasure(int iPos, CTreasureUnit& stTreasureUnit,
            MsgGridItemInfo& stMsgGridItem);

    void GetObjBaseTreasure(CPlayerDetailInfo& stPlayerDetail,
            MsgObjBase& stMsgObjBase, char chHostType, unsigned int uiHostID);

    int GetTreasureFighting(CPlayerDetailInfo& stPlayerDetail,
            char chHostType, unsigned int uiHostID);

    void SendBriefTreasureToFront(CPlayerDetailInfo& stPlayerDetail);

    void GetDetailTreasure(CTreasureUnit& stTreasureUnit,
            MsgTreasureDetail& stMsgDetail);

    void GetObjectDetailTreasure(CPlayerDetailInfo& stPlayerDetail,
            char chHostType, unsigned int uiHostID,
            MsgAnsOtherInfo& stMsgOtherInfo);

	
	void GetTreasureInfo(CPlayerDetailInfo& stPlayerDetail, MsgPlayerInfo& stMsgInfo);

    int GetDetailTreasureInfo(CPlayerDetailInfo& stPlayerDetail,
            short shTreasureID, MsgAnsItemDetailInfos& stMsgDetailInfo);

    void SendDetailTreasureToFront(CPlayerDetailInfo& stPlayerDetail,
            short shTreasureID);

    void SendDetailTreasureToFront(CPlayerDetailInfo& stPlayerDetail,
            const ::google::protobuf::RepeatedField<int64>& stReqIDList);

    int GMDealTreasure(CPlayerDetailInfo& stPlayerDetail,
            MsgReqGMPlayer& stReq, MsgAnsGMPlayer& stAns);

    int GetTreasureList(char chHostType, unsigned int uiHostID,
            CPlayerDetailInfo& stPlayerDetail,
            CTreasureData::T_TREASURE_LIST& astTreasureList);

    int GetTreasureStatusList(char chHostType, unsigned int uiHostID,
            CPlayerDetailInfo& stPlayerDetail, CStatusList& stStatusList);

    int TakeOffPartnerTreasure(short shResID, CPlayerBaseInfo& stPlayerBase,
            CPlayerDetailInfo& stPlayerDetail,
            CPlayerOnlineData& stPlayerOnline);

    bool IsRoleGetTreasure(short shResID,
            CPlayerDetailInfo& stPlayerDetail);

    int RoleGetTreasure(short shResID,
            CPlayerDetailInfo& stPlayerDetail);

    int CheckValidOrder(T_TREASURE_ACT_DATA& aiTreasureOrder);

private:
    CTreasureCfg _stTreasureCfg;
};

#endif // __CTreasureMgr_h__


